package com.jbp.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jbp.domin.WhacMoleReq;
import com.jbp.model.HammerType;
import com.jbp.model.HamsterKind;
import com.jbp.model.HamsterRecord;
import com.jbp.model.Lottery;
import com.jbp.service.*;
import com.jbp.utils.Constant;
import com.jbp.utils.PageUtils;
import com.jbp.utils.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * 地鼠游戏api接口
 */
@Api(tags ="APP接口--地鼠游戏" ,hidden = true)
@ApiIgnore
@RestController
@RequestMapping("/rest/hamster")
public class HamsterController {

    @Autowired
    private HamsterKindService hamsterKindService;

    @Autowired
    private HammerTypeService hammerTypeService;

    @Autowired
    private HamsterService hamsterService;

    @Autowired
    private HamsterRecordService hamsterRecordService;

    @Autowired
    private RankProportionService rankProportionService;

    /**
     * 地鼠种类列表
     * @return
     */
    @GetMapping("/hamsterKindList")
    public R hamsterKindList(){
        List<HamsterKind> hamsterKinds = hamsterKindService.list();
        return R.ok(hamsterKinds);
    }

    /**
     * 锤子种类列表
     * @return
     */
    @GetMapping("/hammerTypeList")
    public R HammerTypeList(){
        List<HammerType> HammerTypes = hammerTypeService.list();
        return R.ok(HammerTypes);
    }

    /**
     * 打地鼠
     * @param whacMoleReq
     * @return
     */
    @PostMapping("/whacMole")
    public synchronized R whacMole(@RequestBody WhacMoleReq whacMoleReq, @RequestAttribute("userId") Integer userId){
        if (userId == null || whacMoleReq.getHamsterKind() == null ||  whacMoleReq.getHammerType() == null){
            return R.error("参数不能为空");
        }
        whacMoleReq.setUserId(userId);
        return hamsterService.whacMole(whacMoleReq);
    }


    /**
     * 排行榜，房间消耗心钻最多
     * @param params
     * @param userId
     * @return
     */
    @GetMapping("/toppeCharts")
    public R toppeCharts(@RequestParam Map<String, Object> params, @RequestAttribute("userId") Integer userId){
//        days int 类型  0 今天 ，1 昨天
        params.put("userId",userId);
        //分页参数
        /*int curPage = 1;
        int limit = 10;
        if(params.get(Constant.PAGE) == null){
            params.put(Constant.PAGE,curPage);
        }
        if(params.get(Constant.LIMIT) == null){
            params.put(Constant.LIMIT,limit);
        }*/
        /*curPage = (Integer.parseInt(params.get(Constant.PAGE).toString())-1) *
                Integer.parseInt(params.get(Constant.LIMIT).toString());
        params.put(Constant.PAGE,curPage) ;*/
        List<HamsterRecord> hamsterRecordList = hamsterRecordService.toppeCharts(params);

//        int count = hamsterRecordService.hamsterRecordCount(params);

        return R.ok(new PageUtils(hamsterRecordList,700,10,1));
    }

    /**
     * 百万奖池房间排行榜
     * @return
     */
    @GetMapping("/prizePoolRank")
    public R prizePoolRank(@RequestParam Map<String, Object> params){
        return rankProportionService.prizePoolRank();
    }

}
